package com.ss.common.taglib;


import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.ss.common.util.AppUtil;
import com.ss.user.pojo.Role;
import com.ss.user.service.RoleService;

/**
 * 角色标签
 * @author Administrator
 *
 */
public class TagRole extends TagSupport{
	private String id;
	private String name;
	private String value;
	
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	private Logger log=Logger.getLogger(TagRole.class);
	@Autowired
	private RoleService roleService;
	@Override
	public int doEndTag() throws JspException {
		if(roleService==null){
			roleService=(RoleService)AppUtil.getBean("roleService");
		}
		StringBuffer buffer=new StringBuffer();
		buffer.append("<select>");
		buffer.append("<option value=''>----</option>");
		Role roles= roleService.queryRole(new Role());
		List<Role> list=roles.pageResult.getList();
		if(roles!=null && list!=null){
			for (int i = 0; i < list.size(); i++) {
				Role temp=list.get(i);
				String name=temp.getName();
				String id=temp.getId();
				String tempChk="";
				if(id.equals(value)){
					tempChk=" selected";
				}
				buffer.append("<option "+tempChk+" value='"+id+"'>");
				buffer.append(name).append("</option>");
			}
		}
		buffer.append("</select>");
		try {
			pageContext.getOut().print(buffer.toString()); 
			buffer.delete(0, buffer.length());
		} catch (Exception e) {
			log.error("权限控件出现异常"+e.getMessage());
		}
		return EVAL_PAGE;
	}
}
